
let riseArr = [5, 3, 8, 1, 12, 4, 6, 7]
let dropArr = [5, 3, 8, 1, 12, 4, 6, 7]
// console.log('升序',riseArr.sort((a,b) => a-b))
// console.log('降序',dropArr.sort((a,b) => b-a))

const mySort = function (callback) {
    for (let i = 0; i < this.length - 1; i++) {
        for (let j = 0; j < this.length - i; j++) {
            if (callback(this[j], this[j + 1]) > 0) {
                let temp = this[j];
                this[j] = this[j + 1];
                this[j + 1] = temp;
            }
        }
    }
    return this;
}
Array.prototype.mySort = mySort;

console.log('升序', riseArr.mySort((a, b) => a - b))
console.log('降序', dropArr.mySort((a,b) => b-a))
